//
//  HZOwnView.m
//  微博 OC
//
//  Created by 黑眼圈 on 16/4/21.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZOwnView.h"
#import "HZHomeCellVM.h"
#import "HZHomeModel.h"
#import <SDWebImage/UIImageView+WebCache.h>

//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND
//define this constant if you want to enable auto-boxing for default syntax
#define MAS_SHORTHAND_GLOBALS



#import <Masonry/Masonry.h>
#import "UILabel+HZSettingLabel.h"

@interface HZOwnView()

@property(nonatomic,strong)UIImageView*  icon;
@property(nonatomic,strong)UILabel*  nameLabel;
@property(nonatomic,strong)UIImageView*  vipMbrank;
@property(nonatomic,strong)UILabel*  created_atLabel;
@property(nonatomic,strong)UILabel*  soureLabel;
@property(nonatomic,strong)UILabel*  myTextLabel;

@end

@implementation HZOwnView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
    }
    return self;
}


#pragma mark -
#pragma mark     添加子控件
-(void)setupUI{
    
    self.icon = [[UIImageView alloc]init];
    self.nameLabel = [[UILabel alloc]init];
    self.vipMbrank = [[UIImageView alloc]init];
    self.created_atLabel = [[UILabel alloc]init];
    self.soureLabel = [[UILabel alloc]init];
    self.myTextLabel = [[UILabel alloc]init];
    
    [self addSubview:self.icon];
    [self addSubview:self.nameLabel];
    [self addSubview:self.vipMbrank];
    [self addSubview:self.created_atLabel];
    [self addSubview:self.soureLabel];
    [self addSubview:self.myTextLabel];
    
    
    //约束
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(10);
        make.width.height.equalTo(35);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(self.icon.trailing).offset(10);
        make.top.equalTo(self.icon);
    }];
    
    [self.vipMbrank makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(self.nameLabel.trailing).offset(10);
        make.top.equalTo(self.nameLabel);
    }];
    
    [self.created_atLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(self.icon.trailing).offset(10);
        make.bottom.equalTo(self.icon);
    }];
    
    [self.soureLabel makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.equalTo(self.created_atLabel.trailing).offset(10);
        make.top.equalTo(self.created_atLabel);
    }];
    
    [self.myTextLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.icon.bottom).offset(10);
        make.leading.equalTo(10);
        
        
    }];
    
    //自动约束高度
    [self makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.myTextLabel.bottom).offset(5);
    }];
    
}


#pragma mark -
#pragma mark     重写模型是set 方法来赋值
-(void)setCellVM:(HZHomeCellVM *)cellVM{
    
    _cellVM =cellVM;
    

    
    NSURL* url = [NSURL URLWithString:cellVM.model.user.profile_image_url];

    [self.icon sd_setImageWithURL:url];
    
    self.nameLabel.text = cellVM.model.user.name;
    
    self.created_atLabel.text = cellVM.model.created_at;
    
    self.soureLabel.text = cellVM.model.source;
    
    self.myTextLabel.text = cellVM.model.text;

    
}



#pragma mark -
#pragma mark     懒加载子控件
-(void)setIcon:(UIImageView *)icon{
    _icon = icon;
    
    icon.image = [UIImage imageNamed:@"avatar_default_big"];
    [icon sizeToFit];
    
//    icon.layer.cornerRadius = 20;
//    icon.layer.masksToBounds=YES;
    
}

-(void)setNameLabel:(UILabel *)nameLabel{
    _nameLabel = nameLabel;
    
    _nameLabel.font = [UIFont systemFontOfSize:14];
    _nameLabel.textColor = [UIColor darkGrayColor];
    
}

-(void)setVipMbrank:(UIImageView *)vipMbrank{
    _vipMbrank = vipMbrank;
    
    _vipMbrank.image = [UIImage imageNamed:@"common_icon_membership_expired"];
    [_vipMbrank sizeToFit];
}


-(void)setCreated_atLabel:(UILabel *)created_atLabel{
    _created_atLabel = created_atLabel;
    
    _created_atLabel.font = [UIFont systemFontOfSize:10];
    _created_atLabel.textColor = [UIColor   orangeColor];
}

-(void)setSoureLabel:(UILabel *)soureLabel{
    _soureLabel= soureLabel;
    
    _soureLabel.font = [UIFont systemFontOfSize:10];
    _soureLabel.textColor = [UIColor darkGrayColor];
}

-(void)setMyTextLabel:(UILabel *)myTextLabel{
    _myTextLabel=myTextLabel;
    
    _myTextLabel.font = [UIFont systemFontOfSize:14];
    _myTextLabel.textColor = [UIColor darkGrayColor];
 
    _myTextLabel.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width-20;
       _myTextLabel.numberOfLines=0;
}




@end
